package com.zccx.eth.util;

public class DomainUtil {
    /**
     * 处理特殊字符串
     * @param str
     * @return
     */
    public static String escapeSpecialChar(String str) {
        String[] stringArr = str.split("");
        String newStr = "";
        for(String s : stringArr){
            if(s.equals("%")) {
                s = s.replace("%","\\%");
            }
            if(s.equals("\\")) {
                s = s.replace("\\","\\\\\\\\");
            }
            if(s.equals("_")) {
                s = s.replace("_","\\_");
            }
            if(s.equals("\'")) {
                s = s.replace("\'","\\'");
            }
            if(s.equals(".")) {
                s = s.replace(".","\\.");
            }
            if(s.equals("*")) {
                s = s.replace("*","\\*");
            }
            newStr += s;
        }
        return newStr;
    }

    public static void main(String[] args) {
        String str = "%sss";
        String str2 = escapeSpecialChar(str);
        System.out.println(str2);
    }
}